package com.cheng.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/provider")
@RefreshScope //获取nacos更新的配置
@Slf4j
public class ProviderController {

    @Value("${book.name}")
    private String bookName;

    @Value("${spring.application.name}")
    private String serverId;

    @Value("${server.port}")
    private int port;

    @GetMapping("/hello")
    public String hello(){
        String message = "服务"+serverId+",端口："+port+",电影名："+bookName;
        log.info("/hello请求成功");
        return message;
    }

    @RequestMapping("/fallback")
    public String testFallBack(@RequestBody boolean flag){
        log.info("testFallBack 接收到的参数为：{}",flag);
        if (flag){
            return "调用成功";
        }else{
            throw new RuntimeException("调用失败");
        }
    }
}
